package com.jsh.controller;

import com.jsh.dao.AttachmentMapper;
import com.jsh.pojo.Attachment;
import com.jsh.service.AttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/Attachment")
public class AttachmentController {
    @Autowired
    private AttachmentService attachmentService;
    @RequestMapping("/list")
    public String list_Attachment(Model model){
        List<Attachment> attachments = attachmentService.selectAll();
        model.addAttribute("list",attachments);
        return "list_Attachment";
    }
    //跳转页面
    @RequestMapping("/toInsert")
    public String toInsertAttachment(){
        return "addAttachment";
    }
    //添加附件
    @RequestMapping("/insert")
    public String InsertAttachment(Attachment attachment){
        System.out.println(attachment.getAttachmentFile());
        attachmentService.insert(attachment);
        return "redirect:/Attachment/list";
    }
    //去修改附件
    @RequestMapping("toUpdate")
    public String toUpdateAttachment(int emailId,Model model){
        Attachment attachment = attachmentService.selectByPrimaryKey(emailId);
        System.out.println(emailId);
        model.addAttribute("attachment",attachment);
        return "updateAttachment";
    }
    //修改附件
    @RequestMapping("/update")
    public String UpdateAttachment(Attachment attachment){
        System.out.println(attachment.getAttachmentFile());
        int i = attachmentService.updateByPrimaryKey(attachment);
        return "redirect:/Attachment/list";
    }
    //删除附件

    @RequestMapping("/delete")
    public String deleteAttachment(int emailId){
        System.out.println(emailId);
        attachmentService.deleteByPrimaryKey(emailId);
        return "redirect:/Attachment/list";
    }

}
